<?php
/**
 * @Author: xuzhiyi
 * @Date:   2016-02-16 20:57:19
 * @Last Modified by:   xuzhiyi
 * @Last Modified time: 2016-02-27 11:52:14
 * ------------------------------------------------ *
 * 支付                                         *
 * ------------------------------------------------ */

namespace Admin\Controller;
class PaymentsController extends CommonController {
	public function index(){
		if(IS_AJAX){
			switch(I('ajax')){
				case "enabled":
					$status = D('Payments')->editStatus(I('ajax'));
					$this->ajaxReturn($status);
					break;
				
				case "addPayments":
					$a = D('Payments')->addPayments();
					if($a){
						$this->success('支付方式添加成功！','',true);	
					}
					$this->error('支付方式添加失败！','',true);
					break;
				case "delPayments":
					$status = D('Payments')->delPayments();
					$this->ajaxReturn($status);
					break;
				case "editPayments":
					$a = D('Payments')->editPayments();
					if($a){
						$this->success('支付方式修改成功！','',true);	
					}
					$this->error('支付方式修改失败！','',true);
					break;
				case "editPay":
					$a = D('Payments')->editPay();
					if($a){
						$this->success('支付方式安装成功！','',true);	
					}
					$this->error('支付方式安装失败！','',true);
					break;
				case "delPay":
					$a = D('Payments')->delPay();
					if($a){
						$this->success('支付卸载成功！','',true);	
					}
					$this->error('支付卸载失败！','',true);
					break;
				default:
					$a=M('payments');
			 		$result = $a->order('payOrder desc')->select();
			 		$output['data'] = $result;
			 		$this->ajaxReturn($output);
			}
		}
		$this->display();
	}

	/* 跳到编辑页面
	 * ------------------- */
	public function editPay(){		
	    $p = D('Payments');
	    $payCode = I("payCode");
    	$pay = array();
    	$pay = $p->getPayments();   	
    	$this->assign('pay',$pay);
		$this->display('pay_'.$payCode);
	}
}